package com.ygxsk.carhome.sys;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.StringUtils;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.event.EventNumber;
import com.ygxsk.carhome.listener.MianTaskManager;
import com.ygxsk.carhome.listener.RxBus;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.rxbus.RxBusEventInfo;

import org.greenrobot.eventbus.EventBus;

import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.Observable;

/**
 * Autuhor:Administrator
 * Time:2019/12/3 0003  09:42
 * Description: this is 创建本地cookies记录
 */
public class Session extends Observable {

    /**
     * 单例的
     */
    public static Session mInstance;

    private final Context mContext;


    // 用户数据_____________________________________________________________
    private String token;

    /**
     * 是否是取消或者退出更新该应用:有可能用户点击了取消,这次不更新.
     */
    private boolean isQuitUpdate = false;

    /**
     * 仅仅执行一次任务时候的标志内容,默认是true 意思是启动APP时候必须打开一次这个任务。
     */
//    private boolean only_once_task = true;


    //用户登录信息相关=========================================================================
    /**
     * 用户的手机号
     */
    private String userPhone;

    /**
     * 存储上次用户登录成功或者失败之后 手动输入的那个登录名称
     */
    private String inputNameLastTime;

    /**
     * 判断当前用户是否登录状态
     */
    private Boolean isLogin;

    /**
     * 记录是否是调试模式 2019/2/16 发现并未用到，废弃
     */
    //private boolean isDebug;
    private String uuid;

    /**
     * 用户的头像信息
     */
    private String photoUrl;

    //岗位角色，职位
    private String workJob;

    /**
     * 用户的id
     */
    private String customerId;
    /**
     * 也是一种用户id信息
     */
    private String customerInfoId;

    /**
     * 小区信息id
     */
    private String communityId;

    /**
     * 该登录用户的区域id内容，它的范围更大
     */
    private String areaId;

    //所在公司的id
    private String companyId;

    //这也是店铺的id
    private String shopInfoId;
    //添加
    private String informationId;

    //获取签署任务的id内容；
    private String signTaskId;

    //这也是店铺的名称 全局只用这一个
    private String shopInfoName;

    //这是所属园区的id
//    private String shopInfoOrCommunityName;


    /**
     * 当前的纯的动态的下载链接
     */
    private String downloadurlcurrent;

    /**
     * 该用户的昵称
     */
    private String nickname;

    //职业信息
    private String occupation;

    /**
     * 用户名称
     */
    private String truename;

    /**
     * 登录时候输入文本框或者登录完毕的登录接口返回来的loginName
     */
    private String loginName;

    /**
     * 设置跳转到社群公告，社区公告详情
     */
    private boolean isPushToBulletinWebview;

    /**
     * 设置强制从社区公告详情退出到首页
     */
    private boolean isPushToBulletinWebviewProce;

    /**
     * 货币符号内容
     */
    private String currencySymbol;

    /**
     * 未读消息的数量,和社区管家做区分的。
     */
    private int totalNumber;

    //================================================================================================

    //---------------------------------------------------------------------------------
    //推送到指定界面的判定+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    private Map<String, String> mapExtra;

    public Map<String, String> getMapExtra() {
        return mapExtra;
    }

    public void setMapExtra(Map<String, String> mapExtra) {
        this.mapExtra = mapExtra;
    }

    //-----------------------------------------------------------------
    //============================================================================================
    /**
     * 设置推送即将跳转到个人中心的我的消息列表即可
     */
    /**
     * 巡检工单池的数据库 内容
     */
    private boolean isPushToMyMessage;

    /**
     * 强制从我的个人消息退出到首页
     */
    private boolean isPushToMyMessageProce;


    public boolean isPushToMyMessage() {
        return isPushToMyMessage;
    }

    public void setPushToMyMessage(boolean pushToMyMessage) {
        isPushToMyMessage = pushToMyMessage;
    }

    //强制退出消息界面的方法
    public boolean isPushToMyMessageProce() {
        return isPushToMyMessageProce;
    }

    public void setPushToMyMessageProce(boolean pushToMyMessageProce) {
        isPushToMyMessageProce = pushToMyMessageProce;
    }


//============================================================================================

    //============================================================================================
    //============================================================================================
    //============================================================================================
    //============================================================================================
    //============================================================================================

    //============================================================================================

    public Session(Context mContext) {

        synchronized (this) {

            this.mContext = mContext;
            readSettings();

        }

    }

    private void readSettings() {

        //默认取出 是否是在整个生命周期之中 只执行一次的任务。
        //only_once_task = SPUtils.getInstance().getBoolean(ConstantApi.ONLY_ONCE_TASK, true);
        //LogUtils.d("itchen---readSettings----only_once_task==>" + only_once_task);

        if (!MMKV.defaultMMKV().decodeBool(ConstantSign.P_SECRECYTURL_AGREE)) {
            uuid = MMKV.defaultMMKV().decodeString(ConstantSign.P_UUID_UNIQUEDEVICEID_ANDROIDID, "");//这里可能市场审核不通过，暂时不获取设备id,因为还没有点击同意
        } else {
            uuid = MMKV.defaultMMKV().decodeString(ConstantSign.P_UUID_UNIQUEDEVICEID_ANDROIDID, DeviceUtils.getUniqueDeviceId());//因为点击了【同意】可以获取设备号
        }

        token = MMKV.defaultMMKV().decodeString(ConstantSign.P_TOKEN, "");

        isLogin = MMKV.defaultMMKV().decodeBool(ConstantSign.P_ISLOGIN, false);

        //truename和loginName是两个能识别用户登录的
        //真实名字是汉字例如陈陈
        truename = MMKV.defaultMMKV().decodeString(ConstantSign.P_TRUENAME, "");

        //登录的账号是英文例如：chenqi
        loginName = MMKV.defaultMMKV().decodeString(ConstantSign.P_LOGINNAME, "");

        nickname = MMKV.defaultMMKV().decodeString(ConstantSign.P_NICKNAME, "");

        photoUrl = MMKV.defaultMMKV().decodeString(ConstantSign.P_PHOTOURL, "");

        //2023-8-4 18:38:36 新增的岗位信息
        workJob = MMKV.defaultMMKV().decodeString(ConstantSign.P_WORKJOB, "");

        userPhone = MMKV.defaultMMKV().decodeString(ConstantSign.P_USERPHONE, "");

        inputNameLastTime = MMKV.defaultMMKV().decodeString(ConstantSign.P_INPUTNAMELASTTIME, "");

        customerId = MMKV.defaultMMKV().decodeString(ConstantSign.P_CUSTOMERID, "");

        customerInfoId = MMKV.defaultMMKV().decodeString(ConstantSign.P_CUSTOMERINFOID, "");

        communityId = MMKV.defaultMMKV().decodeString(ConstantSign.P_COMMUNITYID, "");

        areaId = MMKV.defaultMMKV().decodeString(ConstantSign.P_AREAID, "");
        //法大大企业认证用到
        companyId = MMKV.defaultMMKV().decodeString(ConstantSign.P_COMPANYID, "");

        shopInfoId = MMKV.defaultMMKV().decodeString(ConstantSign.P_SHOPINFOID, "");
        informationId = MMKV.defaultMMKV().decodeString(ConstantSign.P_INFORMATIONID, "");
        signTaskId = MMKV.defaultMMKV().decodeString(ConstantSign.P_SIGNTASKID, "");
        shopInfoName = MMKV.defaultMMKV().decodeString(ConstantSign.P_SHOPINFONAME, "");

        //String customerCenterPurviewListJsonString = SPUtils.getInstance().getString(ConstantApi.P_CUSTOMERCENTERPURVIEWLIST);
//        customerCenterPurviewList = (ArrayList<MineCenterBean>) JSON.parseArray(MMKV.defaultMMKV().decodeString(ConstantApi.P_CUSTOMERCENTERPURVIEWLIST), MineCenterBean.class);
        //LogUtils.d("itchen---->取到的个人中心任务是：" + customerCenterPurviewList);
        nickname = MMKV.defaultMMKV().decodeString(ConstantSign.P_NICKNAME, "");

        occupation = MMKV.defaultMMKV().decodeString(ConstantSign.P_OCCUPATION, "");//职业信息

        //货币符号信息
        currencySymbol = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol));

    }

    public static synchronized Session get(Context con) {
        if (mInstance == null) {
            mInstance = new Session(con);
        }
        return mInstance;
    }

    public void close() {
        mInstance = null;
    }


    //做HTTP的消息头的传递
    public boolean isPushToBulletinWebview() {
        return isPushToBulletinWebview;
    }

    public void setPushToBulletinWebview(boolean pushToBulletinWebview) {
        isPushToBulletinWebview = pushToBulletinWebview;
    }

    public boolean isPushToBulletinWebviewProce() {
        return isPushToBulletinWebviewProce;
    }

    public void setPushToBulletinWebviewProce(boolean pushToBulletinWebviewProce) {
        isPushToBulletinWebviewProce = pushToBulletinWebviewProce;
    }

    /**
     * 取出货币符号
     */
    public String getCurrencySymbol() {

        if (TextUtils.isEmpty(currencySymbol)) {
            currencySymbol = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol));
        }

        return currencySymbol;
    }

    public void setCurrencySymbol(String _currencySymbol) {
        this.currencySymbol = _currencySymbol;

        if (!TextUtils.isEmpty(_currencySymbol)) {
            MMKV.defaultMMKV().encode(ConstantSign.P_CURRENCYSYMBOL, _currencySymbol);
        } else {
            MMKV.defaultMMKV().encode(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol));
        }

    }

    //============================================================================================

    public String getCompanyId() {
        if (TextUtils.isEmpty(companyId)) {
            companyId = MMKV.defaultMMKV().decodeString(ConstantSign.P_COMPANYID, "");
        }
        return companyId;
    }

    public void setCompanyId(String _companyId) {
        this.companyId = _companyId;
        //保存一次切换账号再替换
        LogUtils.d("itchen--_companyId-->" + _companyId);
        MMKV.defaultMMKV().encode(ConstantSign.P_COMPANYID, _companyId);
    }

    //============================================================================================

    /**
     * 用户登录选择的乡村区域id的获取
     */
    public String getAreaId() {
        if (TextUtils.isEmpty(areaId)) {
            areaId = MMKV.defaultMMKV().decodeString(ConstantSign.P_AREAID, "");
        }
        return areaId;
    }

    /**
     * 设置用户最后一级别选择的乡村区域id
     */
    public void setAreaId(String _areaId) {
        this.areaId = _areaId;
        //保存一次切换账号再替换
        //LogUtils.d("itchen--->"+_areaId);
        //itchen--->786
        MMKV.defaultMMKV().encode(ConstantSign.P_AREAID, _areaId);
    }

    public String getCommunityId() {

        if (TextUtils.isEmpty(communityId)) {
            communityId = MMKV.defaultMMKV().decodeString(ConstantSign.P_COMMUNITYID, "");
        }
        return communityId;
    }

    //-------------------------------------------------------------------------------------

    public String getShopInfoId() {
        if (TextUtils.isEmpty(shopInfoId)) {
            shopInfoId = MMKV.defaultMMKV().decodeString(ConstantSign.P_SHOPINFOID, "");
        }
        return shopInfoId;
    }

    public String getShopInfoName() {
        if (TextUtils.isEmpty(shopInfoName)) {
            shopInfoName = MMKV.defaultMMKV().decodeString(ConstantSign.P_SHOPINFONAME, "");
        }
        return shopInfoName;
    }

    //-------------------------------------------------------------------------------------

    public String getInformationId() {
        if (TextUtils.isEmpty(informationId)) {
            informationId = MMKV.defaultMMKV().decodeString(ConstantSign.P_INFORMATIONID, "");
        }
        return informationId;
    }

    public void setInformationId(String _informationId) {
        this.informationId = _informationId;
        MMKV.defaultMMKV().encode(ConstantSign.P_INFORMATIONID, _informationId);
    }

    //-------------------------------------------------------------------------------------
    public String getSignTaskId() {

        if (TextUtils.isEmpty(signTaskId)) {
            signTaskId = MMKV.defaultMMKV().decodeString(ConstantSign.P_SIGNTASKID, "");
        }

        return signTaskId;
    }

    public void setSignTaskId(String _signTaskId) {
        this.signTaskId = _signTaskId;
        MMKV.defaultMMKV().encode(ConstantSign.P_SIGNTASKID, _signTaskId);
    }
    //-------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------

    /**
     * 获取主要的未读消息的数量
     */
    public int getTotalNumber() {
        //如果发现 totalNumber 成了默认的是0，那末，就重新从缓存内取出
        if (totalNumber == 0) {
            totalNumber = MMKV.defaultMMKV().decodeInt(ConstantSign.P_TOTALNUMBER);
        }
        return totalNumber;
    }

    public void setTotalNumber(int _totalNumber) {
        this.totalNumber = _totalNumber;

        MMKV.defaultMMKV().encode(ConstantSign.P_TOTALNUMBER, _totalNumber);

        //LogUtils.d("itchen--setTotalNumber发消息-->" + _totalNumber);
        //这个要发送消息通知商品详情或者团购首页顶部状态栏的.每次都通知刷新也可以。县域特色馆右侧小红点也是这个逻辑。
        //EventBus.getDefault().post(new EventNumber(ConstantApi.EVENTBUS_SHOPCARNUMBER));

        //这里控制购物车右上角红色按钮。确实是刷新了小数字
        EventBus.getDefault().post(new EventNumber(ConstantApi.UPDATE_INFO_ADD, _totalNumber));

    }

    /**
     * 2019年03月23日发现 影响全局
     */
//    public void setCommunityIdAndShopInfoId(String _communityid, String _shopInfoOrCommunityName) {
//
//        //如果不是空值就通知刷新，假如是退出登录等重置为空则不走该逻辑
//        //这个一定要保证设置完毕，因为接口要重新取
//
//        //LogUtils.d("itchen--setCommunityIdAndShopInfoId--发送出去的消息");
//
//        //如下3句话是原始代码，不可删除。
//        SingleHomeEvent singleHomeEvent = new SingleHomeEvent(ConstantApi.NOTIFYDATASET_CHANGED_HOME);
//
//        singleHomeEvent.setCommunityId(_communityid);//第一重要参数
//        //singleHomeEvent.setShopInfoId(_shopInfoId);//第二重要参数,暂时不要了
//        singleHomeEvent.setShopInfoOrCommunityName(_shopInfoOrCommunityName);//第三重要参数
//
//        EventBus.getDefault().post(singleHomeEvent);
//
//    }

    /**
     * 保存和获取两个合并之后的名称  2020年3月12日11:06:59 顶部标题上次选中的社区或者店铺名称。
     */
//    public String getShopInfoOrCommunityName() {
//        if (TextUtils.isEmpty(shopInfoOrCommunityName)) {
//            shopInfoOrCommunityName = MMKV.defaultMMKV().decodeString(ConstantSign.P_SHOPINFOORCOMMUNITYNAME, "");
//        }
//        return shopInfoOrCommunityName;
//    }
//
//    //这个可能是园区的名称 它的范围比店铺的范围更大；
//
//    public void setShopInfoOrCommunityName(String _shopInfoOrCommunityName) {
//        this.shopInfoOrCommunityName = _shopInfoOrCommunityName;
//        //LogUtils.d("itchen---_shopInfoOrCommunityName=" + _shopInfoOrCommunityName);
//        MMKV.defaultMMKV().encode(ConstantSign.P_SHOPINFOORCOMMUNITYNAME, _shopInfoOrCommunityName);
//    }
//
//
//    /**
//     * _shopInfoId会影响整个界面全局的,给影响全局的内容放在这里.
//     */
    public void setShopInfoId(String _shopInfoId) {
        this.shopInfoId = _shopInfoId;
//        LogUtils.d("itchen---_shopInfoId=" + _shopInfoId);
        MMKV.defaultMMKV().encode(ConstantSign.P_SHOPINFOID, _shopInfoId);
    }

    public void setShopInfoName(String _shopInfoName) {
        this.shopInfoName = _shopInfoName;
//        LogUtils.d("itchen---_shopInfoName=" + _shopInfoName);
        MMKV.defaultMMKV().encode(ConstantSign.P_SHOPINFONAME, _shopInfoName);
    }

    /**
     * @date 2018/3/5 0005
     * @auther itchenqi
     * @description 这个_communityid会影响整个界面
     */
    public void setCommunityId(String _communityid) {
        this.communityId = _communityid;
        //先存入信息
        MMKV.defaultMMKV().encode(ConstantSign.P_COMMUNITYID, _communityid);
        SPUtils.getInstance().put(ConstantSign.SP_COMMUNITYID, _communityid);
    }


    /**
     * 在做HTTP请求的时候用到
     */
    public String getUuid() {

        if (TextUtils.isEmpty(uuid)) {
            if (!TextUtils.isEmpty(DeviceUtils.getUniqueDeviceId())) {
                uuid = MMKV.defaultMMKV().decodeString(ConstantSign.P_UUID_UNIQUEDEVICEID_ANDROIDID, DeviceUtils.getUniqueDeviceId());
            } else {
                uuid = MMKV.defaultMMKV().decodeString(ConstantSign.P_UUID_UNIQUEDEVICEID_ANDROIDID, DeviceUtils.getAndroidID());
            }
        }

        return uuid;
    }

    /**
     * 2018年06月05日这个要用在获取用户验证码
     */
    public void setUuid(String _uuid) {
        this.uuid = _uuid;

        if (TextUtils.isEmpty(_uuid)) {
            MMKV.defaultMMKV().encode(ConstantSign.P_UUID_UNIQUEDEVICEID_ANDROIDID, _uuid);
        } else {
            MMKV.defaultMMKV().encode(ConstantSign.P_UUID_UNIQUEDEVICEID_ANDROIDID, DeviceUtils.getUniqueDeviceId());
        }
    }

    /**
     * 2018年06月05日做token加强，在http请求时候要用。
     */
    public String getToken() {

        if (TextUtils.isEmpty(token)) {
            token = MMKV.defaultMMKV().decodeString(ConstantSign.P_TOKEN, "");
        }

        return token;
    }

    /**
     * 本地必然存放的内容
     */
    public void setToken(String _token) {
        this.token = _token;
        SPUtils.getInstance().put(ConstantSign.SP_TOKEN, _token);
        MMKV.defaultMMKV().encode(ConstantSign.P_TOKEN, _token);
    }

    public String getPhotoUrl() {
        //if (TextUtils.isEmpty(photoUrl)) {
        photoUrl = MMKV.defaultMMKV().decodeString(ConstantSign.P_PHOTOURL, "");
        //}
        return photoUrl;
    }

    public void setPhotoUrl(String _photoUrl) {
        this.photoUrl = _photoUrl;
        MMKV.defaultMMKV().encode(ConstantSign.P_PHOTOURL, _photoUrl);
        //头像这一块影响个人中心头像
        RxBus.getInstance().post(new RxBusEventInfo(ConstantApi.RXBUS_MODIFY_AVATAR, _photoUrl));
//        LogUtils.d("itchen---MineFragment--影响发送头像地址信息--_photoUrl=" + _photoUrl);
        //http://222.222.17.184:8990/resource//image/photo/20230805/2023080510025209436931.jpg
    }

    //-------------------------------------------------------------------------------------------------------------
    public String getWorkJob() {
        workJob = MMKV.defaultMMKV().decodeString(ConstantSign.P_WORKJOB, "");
        return workJob;
    }

    public void setWorkJob(String _workJob) {
        this.workJob = _workJob;
        MMKV.defaultMMKV().encode(ConstantSign.P_WORKJOB, _workJob);
//        LogUtils.d("itchen---MineFragment--影响岗位信息--_workJob=" + _workJob);
    }

    //-------------------------------------------------------------------------------------------------------------

    public String getOccupation() {

        if (TextUtils.isEmpty(occupation)) {
            occupation = MMKV.defaultMMKV().decodeString(ConstantSign.P_OCCUPATION, "");
        }

        return occupation;
    }

    /**
     * 存入用户的职业信息
     */
    public void setOccupation(String _occupation) {
        this.occupation = _occupation;
        MMKV.defaultMMKV().encode(ConstantSign.P_OCCUPATION, _occupation);
    }

    //-------------------------------------------------------------------------------------------------------------
    public String getCustomerId() {
        if (TextUtils.isEmpty(customerId)) {
            customerId = MMKV.defaultMMKV().decodeString(ConstantSign.P_CUSTOMERID, "");
        }
        return customerId;
    }

    public void setCustomerId(String _customerId) {
        this.customerId = _customerId;
        MMKV.defaultMMKV().encode(ConstantSign.P_CUSTOMERID, _customerId);
    }

    //-------------------------------------------------------------------------------------------------------------
    public String getCustomerInfoId() {
        if (TextUtils.isEmpty(customerInfoId)) {
            customerInfoId = MMKV.defaultMMKV().decodeString(ConstantSign.P_CUSTOMERINFOID, "");
        }
        return customerInfoId;
    }

    public void setCustomerInfoId(String _customerInfoId) {
        this.customerInfoId = _customerInfoId;
        MMKV.defaultMMKV().encode(ConstantSign.P_CUSTOMERINFOID, _customerInfoId);
    }
    //-------------------------------------------------------------------------------------------------------------

    /**
     * 2018年06月06日添加真实name
     */
    public String getTrueName() {
        if (TextUtils.isEmpty(truename)) {
            truename = MMKV.defaultMMKV().decodeString(ConstantSign.P_TRUENAME, "");
        }
        return truename;
    }

    /**
     * 2018年06月06日添加真实name字段
     */
    public void setTrueName(String _username) {
        this.truename = _username;
        MMKV.defaultMMKV().encode(ConstantSign.P_TRUENAME, _username);
    }

    //-------------------------------------------------------------------------------------------------------------

    /**
     * 取到登录时候的 loginname 字段。
     */
    public String getLoginName() {
        if (TextUtils.isEmpty(loginName)) {
            loginName = MMKV.defaultMMKV().decodeString(ConstantSign.P_LOGINNAME, "");
        }
        return loginName;
    }

    /**
     * 填充设置登录时候
     */
    public void setLoginName(String _loginName) {
        this.loginName = _loginName;
        //SPUtils.getInstance().put(ConstantApi.P_LOGINNAME, _loginName);
    }

    //-------------------------------------------------------------------------------------------------------------

    /**
     * 获取用户上次输入的名称的保存
     */
    public String getInputNameLastTime() {
        if (TextUtils.isEmpty(inputNameLastTime)) {
            inputNameLastTime = MMKV.defaultMMKV().decodeString(ConstantSign.P_INPUTNAMELASTTIME);
        }
        return inputNameLastTime;
    }

    /**
     * 设置用户上次 登录时候 不论成功或者失败，手动输入的那个 登录名称
     */
    public void setInputNameLastTime(String _inputNameLastTime) {
        this.inputNameLastTime = _inputNameLastTime;
        //LogUtils.d("itchen----->被保存的名字==>" + _inputNameLastTime);
        MMKV.defaultMMKV().encode(ConstantSign.P_INPUTNAMELASTTIME, _inputNameLastTime);

    }

    public String getUserPhone() {
        if (TextUtils.isEmpty(userPhone)) {
            userPhone = MMKV.defaultMMKV().decodeString(ConstantSign.P_USERPHONE, "");
        }
        return userPhone;
    }

    public void setUserPhone(String _userPhone) {
        this.userPhone = _userPhone;
        MMKV.defaultMMKV().encode(ConstantSign.P_USERPHONE, _userPhone);
    }

    public final Boolean isLogin() {
        if (!isLogin) {
            isLogin = MMKV.defaultMMKV().decodeBool(ConstantSign.P_ISLOGIN, false);
        }
        return isLogin;
    }

    public final void setLogin(Boolean _isLogin) {
        this.isLogin = _isLogin;
        MMKV.defaultMMKV().encode(ConstantSign.P_ISLOGIN, _isLogin);
    }

    public static void pushOneActivity(Activity actvity) {

        MianTaskManager.getInstance(actvity).pushOneActivity(new WeakReference<Activity>(actvity));
    }

    public String getNickName() {

        if (TextUtils.isEmpty(nickname)) {
            nickname = MMKV.defaultMMKV().decodeString(ConstantSign.P_NICKNAME, "");
        }

        return nickname;
    }

    public void setNickName(String _nickname) {
        this.nickname = _nickname;
        //LogUtils.d("itchen--填充昵称-->"+_nickname);
        if (!TextUtils.isEmpty(_nickname)) {
            MMKV.defaultMMKV().encode(ConstantSign.P_NICKNAME, _nickname);
        } else {
            MMKV.defaultMMKV().encode(ConstantSign.P_NICKNAME, "");
        }
    }

    /**
     * @return boolean
     * @Title: isUpdate
     * @Description: 获取当前是否是更新应用的标志，
     * 这个暂时还没有十分的必要存在sharepreference之中，只在当次启动的内存之中有效。
     */
    public boolean isQuitUpdate() {
        //boolean updatValue = PreferenceManager.getInstance().getSaveBooleanData(ConstantApi.ISUPDATE, false);
        return isQuitUpdate;
    }

    public void setQuitUpdate(boolean isUpdate) {
        //LogUtils.d("itchen---setisquitflag=" + isUpdate);
        //PreferenceManager.getInstance().saveData(ConstantApi.ISUPDATE, isUpdate);
        this.isQuitUpdate = isUpdate;
    }

    public String getDownloadurlCurrent() {

        if (TextUtils.isEmpty(downloadurlcurrent)) {

            downloadurlcurrent = MMKV.defaultMMKV().decodeString(ConstantSign.APP_UPDATE_ANDROID_DOWNLOAD_URL, "");
        }

        return downloadurlcurrent;
    }

    /**
     * 内存之中存入当前完整的下载链接，不用保存在本地，动态即可
     */
    public void setDownloadurlCurrent(String _downloadurlcurrent) {
        this.downloadurlcurrent = _downloadurlcurrent;
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "存入的下载地址是=>" + _downloadurlcurrent);
        MMKV.defaultMMKV().encode(ConstantSign.APP_UPDATE_ANDROID_DOWNLOAD_URL, _downloadurlcurrent);//本地再存一份
    }

    public void setPublic_url_prefix(String _public_url_prefixnew) {

        //LogUtils.d("itchen--setPublic_url_prefix--->"+_public_url_prefixnew);

        NetworkManager.getInstance().setPublic_url_prefix_form_getSystemConfig(_public_url_prefixnew);//内存里存一份

        MMKV.defaultMMKV().encode(ConstantSign.PUBLIC_URL_PREFIX, _public_url_prefixnew);//本地再存一份

        //2018年06月07日，做下次假如没有调用成功的历史记录
        MMKV.defaultMMKV().encode(ConstantSign.PUBLIC_URL_PREFIX_LASTTIME, _public_url_prefixnew);

        //MMKV.defaultMMKV().encode(ConstantApi.PUBLIC_URL_PREFIX_LASTTIME, getReleaseInManger() ? ApiService.OFFICIAL_BASEURL : ApiService.TEST_BASEURL);

    }

    public static void finishAllActivity(Context context) {
        MianTaskManager.getInstance(context).finishAllActivity();
    }

    public static void handlerFragment(View viewfragment) {

        ViewGroup parent = (ViewGroup) viewfragment.getParent();

        if (parent != null) {
            //LogUtils.d("itchen--即将执行--parent.removeView");
            parent.removeView(viewfragment);
        } else {
            //LogUtils.d("itchen--不执行--parent.removeView");
        }

    }

    //================================================================================================
    //================================================================================================
    //================================================================================================
    //处理图片的信息方法
    //================================================================================================

}
